Attribute VB_Name = "Inireader"
Private Type inisection
    nme As String
    vnme() As String
    vval() As String
End Type

Dim inis() As inisection
Dim cinifile As String


Public Sub setini(fname As String)
cinifile = fname
loadini
End Sub

Public Function getval(nme As String, Optional context As String = "Default")
For x = 0 To UBound(inis)
If UCase(inis(x).nme) = UCase(context) Then
    For y = 0 To UBound(inis(x).vnme)
    If UCase(inis(x).vnme(y)) = UCase(nme) Then
        getval = inis(x).vval(y)
        Exit Function
    End If
    Next y
End If
Next x
End Function

Public Sub loadini()
If Dir(cinifile) = "" Then Exit Sub 'if it doesn't exist, don't load it
Open cinifile For Input As #1
Dim x As String
Dim ui As Double
Dim uv As Double
ReDim inis(0)

Do Until EOF(1)

Do
Line Input #1, x
Loop Until Left(x, 1) <> ";" And Trim(x) <> "" 'Get rid of comments and blank lines

If Left(x, 1) = "[" Then 'Find the first section
    If Right(x, 1) = "]" Then
        x = Mid(x, 2, Len(x) - 2)
        ui = ui + 1
        ReDim Preserve inis(ui)
        inis(ui).nme = x
        uv = 0
    End If
Else
    If ui > 0 Then 'We've found our first section
        If InStr(1, x, " = ") > 0 Then 'we have a value
            cnme = Mid(x, 1, InStr(1, x, " = ") - 1)
            cval = Mid(x, InStr(1, x, " = ") + 3)
            ReDim Preserve inis(ui).vnme(uv)
            ReDim Preserve inis(ui).vval(uv)
            inis(ui).vnme = cnme
            inis(ui).vval = cval
        End If
    End If
End If
Loop
Close #1
End Sub

